<?php

namespace app\api\controller;


use app\common\controller\Api;
use think\Log;
use app\api\model\BaseModel;
use think\Db;
use app\api\service\JsonService;
class Recruit extends Api
{
    //招募控制器

    // https://keguan.cc/api/Recruit/ocrnotify

    
    protected $noNeedLogin = ['ocrnotify'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function ocrnotify($id)
    {
                // 允许来自所有源的请求
        header("Access-Control-Allow-Origin: *");
        // 允许的请求方法
        header("Access-Control-Allow-Methods: POST");
        // 允许的请求头
        header("Access-Control-Allow-Headers: Content-Type");
        // 响应类型
        header("Content-Type: application/json");
        $file = 'ocrnotify';
        $testxml = file_get_contents("php://input");
        if($testxml){
            BaseModel::log($file, $testxml.$id);
            $data = json_decode($testxml,true);
            $json = json_encode($data['data']);
            $result = Db::table('hs_member_ocr')->where('member_id',$id)->field('id')->find();
            if($result){
                $res = Db::table('hs_member_ocr')->where('member_id', $id)->update(['content'=> $json,'updatetime'=>date('Y-m-d H:i:s')]);
            }else{
                $res = Db::table('hs_member_ocr')->insert(['member_id'=>$id,'content'=>$json,'createtime'=>date('Y-m-d H:i:s')]);
            }
            if($res){
                return JsonService::successful('成功');
            }
        }
        return JsonService::fail('参数错误');
    }
    
}